package com.ganlinux.pangoo.controller.restful.app;

import com.alibaba.fastjson.JSON;
import com.ganlinux.pangoo.controller.restful.base.BaseController;
import com.ganlinux.pangoo.entity.request.ReqCheckUpdate;
import com.ganlinux.pangoo.entity.request.ReqFootPrintSimpleInfoList;
import com.ganlinux.pangoo.entity.response.RspCheckUpdateData;
import com.ganlinux.pangoo.entity.response.base.RspBase;
import com.jfinal.aop.Before;
import com.jfinal.kit.HttpKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

/**
 * BlogController
 * 所有 sql 与业务逻辑写在 Model 或 Service 中，不要写在 Controller 中，养成好习惯，有利于大型项目的开发与维护
 */
@Before(CheckUpdateInterceptor.class)
public class CheckUpdateController extends BaseController {
	public void save() {
		RspBase rspLogin = new RspBase();
		String jsonString= HttpKit.readData(getRequest());
		ReqCheckUpdate reqLogin = JSON.parseObject(jsonString, ReqCheckUpdate.class);
		reqLogin.setReqHeader(getHeaderFromRequest(getRequest()));
		String reqVerifyCode = reqLogin.getCurrentVersion();
		RspCheckUpdateData rspCheckUpdateData = new RspCheckUpdateData();
		Record re = Db.findFirst("select * from VersionConfig where id = '1'");
		int lastedVersion = Integer.parseInt(re.getStr("versionnum"));
		/*if (lastedVersion>reqVerifyCode) {
			rspCheckUpdateData.setNeedUpdate(true);
			rspCheckUpdateData.setLastedVersion(re.getStr("versionnum"));
			rspCheckUpdateData.setUpdateDesc(re.getStr("updatedesc"));
			rspCheckUpdateData.setUpdateFileName(re.getStr("updatefilename"));
			rspCheckUpdateData.setUpdateUrl(re.getStr("updateUrl"));
		}else{
			rspCheckUpdateData.setNeedUpdate(false);
		}*/
		rspLogin.setData(rspCheckUpdateData);
		renderText(JSON.toJSONString(rspLogin));

	}

	public void edit() {
		super.edit();
	}

	public void update() {
		super.update();
	}

	public void delete() {
		super.delete();
	}
}


